﻿@*YoursLC有源低代码 Create:admin 2023-07-04 14:31:00 添加或编辑-此文件放置于Views/ProductManagement /中*@

@using Think9.Models;
@*@model Think9.Models.ProductManagementModel;*@
@{ ViewBag.Title = "Add";
	Layout = "~/Areas/Shared/_LayuiForm.cshtml"; }

@*货品管理 ---录入表样式按照默认方式一行两列生成，可能是因为未设计表单样式*@

<form class="layui-form layui-form-pane" lay-filter="formUser">
<input style="display:none" id="_isDebug" value="debug">@*debug为调试；release为发布*@
<input style="display:none" id="_listid" value="@ViewBag.ListId">
<input style="display:none" id="_plit" value="@ViewBag.Split">@*多选框字符分割*@
<input style="display:none" id="_frm" value="@ViewBag.Frm">@*从哪里跳转来的?默认list*@
<input style="display:none" id="_type" value="@ViewBag.Type">@*add或edit*@
<input style="display:none" id="_userid" value="@ViewBag.UserId">@*用户id*@
<input style="display:none" id="_attachmentId">@*附件id*@
<input style="display:none" id="_fwid" value="@ViewBag.FId">@*当前流程编码*@
<input style="display:none" id="prc_id" value="@ViewBag.PrcId">@*当前流程步骤id*@
<input style="display:none" id="prc_no" value="@ViewBag.PrcNo">@*当前流程步骤编码*@
@*弹出选择时页面间传递数据*@
<input style="display:none" id="pu_value">@*弹出选择时使用-弹出页面选择的值*@
<input style="display:none" id="pu_tbid">@*弹出选择时使用-触发弹出页面的表id，_main或子表编码*@
<input style="display:none" id="pu_indexid">@*弹出选择时使用-触发弹出页面的指标编码*@
<input style="display:none" id="pu_rowid">@*弹出选择时使用-子表弹出，对应tableid 哪一行*@
<input style="display:none" id="pu_column">@*弹出选择时使用-子表弹出，第几列*@
<div class="layui-form">
 <div class="layui-form-item"  style="text-align: right;">
	<div class="layui-btn-container">
			@*<a href="" target="_blank" id="print" class="layui-btn">打印</a>*@
			<button type="button" class="layui-btn" id="att">附件</button>
			<button type="button" class="layui-btn" lay-submit lay-filter="edit" id="edit">保存</button>
			@*<button type="button" class="layui-btn" lay-submit lay-filter="next"  id="next">转交</button>*@
			@*<button type="button" class="layui-btn" lay-submit lay-filter="finish" id="finish">结束</button>*@
	 </div>
  </div>

	<div class="layui-row layui-col-space10">
		<div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
			<label class="layui-form-label required">货品编码</label>
			<div class="layui-input-block">
				<input type='text' name='inHPBM' id='inHPBM' autocomplete='off' class='layui-input'  maxlength='10'    lay-verify='required'  placeholder='货品编码'>
				</div>
			</div>
		<div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
			<label class="layui-form-label required">货品名称</label>
			<div class="layui-input-block">
				<input type='text' name='inHPMC' id='inHPMC' autocomplete='off' class='layui-input'  maxlength='30'    lay-verify='required'  placeholder='货品名称'>
				</div>
			</div>
	 </div>
	<div class="layui-row layui-col-space10">
		<div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
			<label class="layui-form-label">规格型号</label>
			<div class="layui-input-block">
				<input type='text' name='inGGXH' id='inGGXH' autocomplete='off' class='layui-input'  maxlength='100'     placeholder='规格型号'>
				</div>
			</div>
		<div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
			<label class="layui-form-label required">所属类别</label>
			<div class="layui-input-block">
				<select id="inSSLB" name="inSSLB"  lay-filter = "inSSLB"   lay-verify='required' >
					<option value="">==请选择==</option>
						@foreach (valueTextEntity item in ((IEnumerable<valueTextEntity>)ViewBag.SelectList).Where(x => x.ClassID == "inSSLB"))
						{
							 <option value="@item.Value">@item.Text</option>
						}
				</select>
				</div>
			</div>
	 </div>
	<div class="layui-row layui-col-space10">
		<div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
			<label class="layui-form-label required">计量单位</label>
			<div class="layui-input-block">
				<select id="inJLDW" name="inJLDW"  lay-filter = "inJLDW"   lay-verify='required' >
					<option value="">==请选择==</option>
						@foreach (valueTextEntity item in ((IEnumerable<valueTextEntity>)ViewBag.SelectList).Where(x => x.ClassID == "inJLDW"))
						{
							 <option value="@item.Value">@item.Text</option>
						}
				</select>
				</div>
			</div>
		<div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
			<label class="layui-form-label">成本价</label>
			<div class="layui-input-block">
				<input type='text' name='inCBJ' id='inCBJ' autocomplete='off' class='layui-input'   maxlength='15'    lay-verify='number'   placeholder='成本价'>
			</div>
		</div>
	 </div>
	<div class="layui-row layui-col-space10">
		<div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
			<label class="layui-form-label">销售价</label>
			<div class="layui-input-block">
				<input type='text' name='inXSJ' id='inXSJ' autocomplete='off' class='layui-input'   maxlength='15'    lay-verify='number'   placeholder='销售价'>
			</div>
		</div>
		<div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
			<label class="layui-form-label">最低库存</label>
			<div class="layui-input-block">
				<input type='text' name='inZDKC' id='inZDKC' autocomplete='off' class='layui-input'   maxlength='15'    lay-verify='number'   placeholder='最低库存'>
			</div>
		</div>
	 </div>
	<div class="layui-row layui-col-space10">
		<div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
			<label class="layui-form-label">最高库存</label>
			<div class="layui-input-block">
				<input type='text' name='inZGKC' id='inZGKC' autocomplete='off' class='layui-input'   maxlength='15'    lay-verify='number'   placeholder='最高库存'>
			</div>
		</div>
		<div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
			<label class="layui-form-label">默认供应商</label>
			<div class="layui-input-block">
				<input type='text' name='inMRGYS' id='inMRGYS' autocomplete='off' class='layui-input'  maxlength='10'     placeholder='默认供应商'>
				</div>
			</div>
	 </div>
	<div class="layui-row layui-col-space10">
		<div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
			<label class="layui-form-label">启用|停用</label>
			<div class="layui-input-block">
				@foreach (valueTextEntity item in ((IEnumerable<valueTextEntity>)ViewBag.SelectList).Where(x => x.ClassID == "inQYTY"))
				{
					<input type="radio"  name="@item.ClassID" value="@item.Value" title="@item.Text">
				}
				</div>
			</div>
		<div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
			<label class="layui-form-label">条形码</label>
			<div class="layui-input-block">
				<input type='text' name='inTXM' id='inTXM' autocomplete='off' class='layui-input'  maxlength='100'     placeholder='条形码'>
				</div>
			</div>
	 </div>
	<div class="layui-row layui-col-space10">
		<div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
			<label class="layui-form-label">货品图片</label>
			<div class="layui-input-block">
				<input style='display:none' id='inHPTP_Exa'  name='inHPTP_Exa'>
				<span> <img id='inHPTP'  src='~/images/nonexistent.gif' alt='nonexistent.gif' style='height:125px;width:125px;'>  </span>
			</div>
		</div>
		<div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
			<label class="layui-form-label">备注</label>
			<div class="layui-input-block">
				<input type='text' name='inRemarks' id='inRemarks' autocomplete='off' class='layui-input'  maxlength='200'     placeholder='备注'>
				</div>
			</div>
	 </div>
	<div class="layui-row layui-col-space10">
		<div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
			<label class="layui-form-label">备注02</label>
			<div class="layui-input-block">
				<input type='text' name='inNote02' id='inNote02' autocomplete='off' class='layui-input'  maxlength='200'     placeholder='备注02'>
				</div>
			</div>
	 </div>
</div>

</form>
<script>
	layui.config({
		base: '/self_js/'  /*自定义的js 在wwwroot/self_js文件夹中*/
	});
	layui.use(["form", "exLayer", "element", "exUtils",  "table", "ProductManagement"], function () {
		let form = layui.form;
		let layer = layui.layer;
		let table = layui.table;
		let exLayer = layui.exLayer;
		let exUtils = layui.exUtils;
		let element = layui.element;
		let myJS = layui.ProductManagement;
		let $ = layui.$;

		form.render();
		getFormVal();//控件赋值-复选框和图片

		//Tab选项  
		element.on('tab(tabDemo)', function (data) {
        });
		//赋值--不包括多选框和图片
		form.val("formUser", {
			"inHPBM": "@Model.inHPBM"
			,"inHPMC": "@Model.inHPMC"
			,"inGGXH": "@Model.inGGXH"
			,"inSSLB": "@Model.inSSLB"
			,"inJLDW": "@Model.inJLDW"
			,"inCBJ": "@Model.inCBJ"
			,"inXSJ": "@Model.inXSJ"
			,"inZDKC": "@Model.inZDKC"
			,"inZGKC": "@Model.inZGKC"
			,"inMRGYS": "@Model.inMRGYS"
			,"inQYTY": "@Model.inQYTY"
			,"inTXM": "@Model.inTXM"
			,"inRemarks": "@Model.inRemarks"
			,"inNote02": "@Model.inNote02"
		});
		//自定义控件赋值，用于多选框和图片的显示等
		function getFormVal() {

			//货品图片
			$('#inHPTP_Exa').val('@Model.inHPTP');
			$('#inHPTP').attr('alt', '@Model.inHPTP');//
			if ($('#inHPTP_Exa').val() == '') {
				$('#inHPTP').attr('src', '/images/nonexistent.gif'); 
			}
			else{
				$('#inHPTP').attr('src', '/UserImg/@Model.inHPTP');
			}

		}
		$('#inHPTP').on('click', function () {
			exLayer.open('图片上传', '/Com/FileManage/PictureUplaod?tbid=tb_ProductManagement&indexid=inHPTP&from=add&fname=' + $('#inHPTP')[0].alt, '100%', '100%', '0px', '0px', null, null);
		});




		$('#att').on('click', function () {
			exLayer.open('附件上传', '/Com/FileManage/Attachment?fwid=' + $('#_fwid').val() + '&listid=' + $('#_listid').val() + '&prcid=' + $('#prc_id').val() + '&userid=' + $('#_userid').val() + '&attid=' + $('#_attachmentId').val(), '100%', '100%', '0px', '0px', null, null);
		});
		//点击保存按钮
		form.on("submit(edit)", function (data) {
			var _gridList = myJS.foreachGridTable();//遍历子表取数，在自定义js中定义
			exUtils.ajax('/_TB/SaveData', 'post', {
				model: data.field, 'gridlist': _gridList, listid: $('#_listid').val(), prcno: $('#prc_no').val(), type: $('#_type').val(), att: $('#_attachmentId').val(), fwid: $('#_fwid').val(), json: JSON.stringify(data.field, null, 4) }, true).done(function (response) {
				exLayer.greenTickMsg(response.message, function () {
				if ($('#_frm').val() == 'list') {
					//从list页面跳转需刷新列表
					$(window.parent.document).find('#search').click();
				}
				parent.layer.close(parent.layer.getFrameIndex(window.name));
			});
		}).fail(function (error) {
			console.log(error);
		});
			return false;
		});


		//子表刷新
		function tableRender(tbid) {
		//什么也不做,因为无子表，但得有--readValue函数中需要调用
		}

        table.on("toolbar(tableFilter)", function (obj) {
            switch (obj.event) {
                case "_event":
                    break;

            }
        });

		//弹出页面关闭后为控件赋值并执行数据读取 无弹出页面可删除
		$("#pu_value").click(function () {
			myJS.getValueFromPopUp();//弹出页面关闭后，将选择的Value赋值给触发弹出页面的input，在自定义js中定义
			readValue();//执行数据读取，每个弹出都触发--可手动优化
		});

		//数据读取
		function readValue() {
			var _gridList = myJS.getCurrentGridTable($('#pu_tbid').val(), $('#pu_rowid').val());
            var _controlsList = myJS.getControlValueList();//主表所有控件ID和Value，在自定义js中定义

			exUtils.ajax("/_TB/AfterControlSelect", "post", { controlslist: _controlsList, "gridlist": _gridList, id: $('#pu_rowid').val(), tbid: $('#pu_tbid').val(), indexid: $('#pu_indexid').val(), value: $('#pu_value').val(), fwid: $('#_fwid').val(), listid: $('#_listid').val() }, true).done(function (response) {
				var lists = response.list;
				var _listid = response.extra;
                var _grid = response.extra2;
				if (_listid != "") {
                    $('#_listid').val(_listid)
                }
                if (lists != null) {
                    //console.log(lists);
                    myJS.setValueByList(lists);//使用后台返回的lists，为控件赋值，在自定义js中定义
				}
				if (_grid != "") {
                    tableRender(_grid);//子表数据刷新
				}

				form.render();//一定要加
			}).fail(function (error) {
				console.log(error);
			});

			return false;
		}

		//打印
        function setPrint() {
            $("#print").attr("href", "/_TB/Print?listid=" + $('#_listid').val() + "&type=pdf&fwid=" + $('#_fwid').val());
        }

		//消息提示
        $(document).on("mouseenter", "*[lay-tips]", function () {
            var remind = $(this).attr("lay-tips");
            var tips = $(this).data("offset") || 4;
            var color = $(this).data("color") || '#88858e';
            layer.tips(remind, this, {
                time: -1,
                tips: [tips, color],
                area: ['auto', 'auto'],
            });
        }).on("mouseleave", "*[lay-tips]", function () {
            layer.closeAll("tips");
        });

		$(document).ready(function () {
		    setPrint();//打印
			myJS.lockForEditing($('#_type').val());//编辑时锁定
			myJS.setFormButDisable("@ViewBag.DisableBut");//控制页面按钮状态
		    myJS.setStateByFlow($('#prc_no').val());//根据步骤编码设置控件disabled属性
			form.render('select');//要加上，否则下拉选择disabled设置无效

			if (layui.device().mobile) {
				//手机端
				$(".layui-btn").attr("class", "layui-btn layui-btn-sm");
            }
        });
	});
</script>